import { current } from "../../../../api/current"

export default {
    namespaced: true,
    state: {
        //未读消息数量
        unreadMessageCount: {
            total: 0,
            sys_num: 0,
            order_num: 0
        },
        //消息通知配置
        messageConfig: {
            message_volice: false,
            message_dialog: false
        }
    },
    mutations: {
        setUnreadMessageCount(state, count) {//未读消息数量
            state.unreadMessageCount = count;
        },
        setMessageConfig(state, count) {//未读消息数量
            state.messageConfig = count;
        }
    },
    actions: {
        // 获取未读消息数量
        getCount({ commit }) {
            let data = {
                hotel_id: sessionStorage.getItem('hotel_id')
            }
            current('supplier/message/no-read', data, 'get').then(res => {
                // console.log(res.data, '获取未读消息数量');
                let { code, data } = res.data
                if (code === 200) {
                    commit('setUnreadMessageCount', data); // 调用mutation来更新未读消息数量
                }
            })
        },
        // 获取消息通知配置
        getMessageConfig({ commit }) {
            let data = {
                hotel_id: sessionStorage.getItem('hotel_id')
            }
            current('supplier/hotel-pms-message', data, 'GET').then(res => {
                // console.log(res.data, '获取消息通知配置结果');
                // 1 开启  0 关闭
                let { code, data } = res.data
                if (200 == code) {
                    data.message_volice = data.message_volice == 0 ? false : true
                    data.message_dialog = data.message_dialog == 0 ? false : true
                    commit('setMessageConfig', data); // 调用mutation来更新消息通知配置
                }
            })
        }
    },
}